package com.sang.lesson03;

import com.sang.lesson02.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Date;


public class TestUpdate {
    public static void main(String[] args) {
        Connection conn =null;
        PreparedStatement st = null;

        try {
            conn = JdbcUtils.getConnection();//获取数据库连接

            //区别
            //使用？ 占位符代替参数
            String sql = "UPDATE users SET `NAME` = ?,`email`=? WHERE id=?";

            st = conn.prepareStatement(sql);//预编译SQL，先写sql，然后不执行

            //手动给参数赋值
            st.setString(1,"kuangshen");
            st.setString(2,"24736743@qq.com");
            st.setInt(3,1);

            int i = st.executeUpdate(sql);
            if(i>0){
                System.out.println("更新成功！");
            }
            JdbcUtils.release(conn,st,null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}